package com.study.leetcode;

//https://leetcode-cn.com/problems/sort-colors/
public class Solution_75 {
    public void sortColors1(int[] nums) {
        int temp;
        for (int i = 0; i < nums.length; i++) {
            for (int j = 1; j < nums.length; j++) {
                if (nums[j - 1] > nums[j]) {
                    temp = nums[j - 1];
                    nums[j - 1] = nums[j];
                    nums[j] = temp;
                }

            }
        }
    }

    public void sortColors(int[] nums) {
        int count1 = 0, count2 = 0, temp;
        for (int i = 0; i < nums.length; i++) {
            temp = nums[i];
            nums[i] = 2;
            if (temp < 2) {
                nums[count2++] = 1;
            }
            if (temp < 1) {
                nums[count1++] = 0;
            }
        }
    }
}
